package com.example.anyong17_julnumgi.test;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.SumPathEffect;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class RecordActivity extends Activity {
	ArrayList<Record>arRecord = new ArrayList<Record>();
	int date_count=0;
	
	TextView mTime;
	TextView mCount;
	
	Today today=new Today();
	String mainToday=today.dTime;
	
	String filename = mainToday+date_count;
	
	String str = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.recordactivity);
		
		Intent intent = getIntent();
		arRecord = intent.getParcelableArrayListExtra("Recoders");
		
		mTime = (TextView) findViewById(R.id.record_tv1);
		mCount= (TextView) findViewById(R.id.record_tv2);
		mCount.setTextSize(20);
		mTime.setTextSize(20);
		
		
			
		
			
			if(arRecord.isEmpty()==true){//기록이 없을시 처리
				mTime.setText(mainToday+"\n");
				
			}else{//줄넘기에서 넘어온 기록 처리
					str = "=======================\n";
				for(int i = 0;i<arRecord.size();i++){
					String count = arRecord.get(i).counter; 
					String time = arRecord.get(i).time;
					str+=String.format("%s 바퀴 %s 초\n", count ,time);
					}
				mTime.setText(mainToday+"\n");
				mCount.setText(str);
			}
			
			
			
			
			
	}
	@Override
	protected void onResume() {
		super.onResume();
	}
	public void mOnClick (View v){
		switch (v.getId()){
			case R.id.record_btn1:
				/*try{
					FileOutputStream fos = openFileOutput(filename+".txt", MODE_PRIVATE);
					fos.write(str.getBytes());
					fos.close();
					}catch(Exception e){;}
					Toast.makeText(RecordActivity.this, "save", Toast.LENGTH_LONG).show();*/
				break;
			case R.id.record_btn2:
				/*try{
					FileInputStream fis = openFileInput(filename+".txt");
					byte[] data = new byte[fis.available()];
					while (fis.read(data)!=-1) {;}
					fis.close();
					mCount.setText(new String(data));
					}catch (Exception e) {;}*/
					break;
			case R.id.record_btn3:
				deleteFile(filename+".txt");
				break;
		}
		}
	private void loadfile() {
		try{
			FileInputStream fis = openFileInput(filename+".txt");
			byte[] data = new byte[fis.available()];
			while (fis.read(data)!=-1) {;}
			fis.close();
			mCount.setText(new String(data));
			}catch (Exception e) {;}
	}
	private void savefile() {
		try{
			FileOutputStream fos = openFileOutput(filename+".txt", MODE_APPEND);
			fos.write(str.getBytes());
			fos.close();
			}catch(Exception e){;}
	}
}


